package cn.cjj.gulimall.cart.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author CuiJunJie
 * @create 2021/7/6-16:48
 */
@Data
public class Cart {
    private List<CartItem> items;
    private Integer countNum;
    private Integer countType;
    private BigDecimal totalAmount;
    private BigDecimal reduce = new BigDecimal("0");

    public Integer getCountNum() {
        int count = 0;
        if (items != null && items.size() > 0) {
            for (CartItem item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public Integer getCountType() {
        if (items == null) {
            return 0;
        }

        return items.size();
    }

    public BigDecimal getTotalAmount() {
        BigDecimal total = new BigDecimal("0");
        if (items != null) {
            for (CartItem item : items) {
                if (item.getCheck()) {
                    total = total.add(item.getTotalPrice());
                }
            }
        }

        total.subtract(getReduce());

        return total;
    }

    public BigDecimal getReduce() {
        return reduce;
    }
}
